<template>
  <div class="${modelName?uncap_first}BaseType">
    <zk-row class="top">
      <zk-menu-crumb></zk-menu-crumb>
      <zk-search-input
        :placeholder="$t('${moduleName}_${modelName?uncap_first}_name')"
        v-model="searchParams.name$like"
        @click="queryHandler"
        icon="fa fa-search"
      >
      </zk-search-input>
    </zk-row>
    <zk-row :gutter="12">
      <zk-col :span="24">
        <zk-widget>
          <div slot="header">
            <zk-tool-bar @add="openDialog">
            </zk-tool-bar>
          </div>
          <div>
            <${vueTab?uncap_first}-list ref="${modelName?uncap_first}List" @edit="openDialog" :searchParams="searchParams"></${vueTab?uncap_first}-list>
          </div>
        </zk-widget>
      </zk-col>
    </zk-row>
    <zk-dialog v-model="${modelName?uncap_first}DialogVisible" :title="dialogTitle" size="small" width="650px" @close="handlerEditClose">
       <zk-edit-${vueTab?uncap_first} :current-model-form="currentRow" @edit-change="isEdit" :isEdit="editDialog" ref="${modelName?uncap_first}Ref"></zk-edit-${vueTab?uncap_first}>
    </zk-dialog>
  </div>  
</template>
<script>
  import ${modelName?cap_first}List from './List${modelName?cap_first}.vue'
  import ZkEdit${modelName?cap_first} from './Edit${modelName?cap_first}.vue'
  export default {
    data() {
      return {
        searchParams: {
          name$like: ''
        },
        currentRow: {
        <#assign size1 = 0>
         <#list fields as field>
          <#if field.name != 'id' && field.type != 'Timestamp' && field.type != 'Date'>
          	<#assign size1 = size1 + 1>
          </#if>
         </#list>
         <#assign num = 1>
          <#list fields as field>
          <#if field.name != 'id' && field.type != 'Timestamp' && field.type != 'Date'> 
          ${field.name}: ''<#if num != size1>,</#if>
			<#assign num = num + 1>
           </#if>
		 </#list>
        },
        editDialog: false,
        ${modelName?uncap_first}DialogVisible: false,
        dialogTitle: this.$t('${moduleName}_${modelName?uncap_first}_title')
      }
    },
    methods: {
      openDialog(row, isEdit) {
        if (!isEdit) {
          this.editDialog = false
          this.dialogTitle = this.$t('${moduleName}_${modelName?uncap_first}_title')
          this.${modelName?uncap_first}DialogVisible = true
        } else {
          this.currentRow = this.$clone(row)
          this.editDialog = true
          this.${modelName?uncap_first}DialogVisible = true
        }
      },
      isEdit (val) {
        this.editDialog = val
      },
      queryHandler() {
        this.$refs.${modelName?uncap_first}List.setParams(this.searchParams)
        this.$refs.${modelName?uncap_first}List.search()
      },
      handlerEditClose() {
        this.$refs.${modelName?uncap_first}List.search()
        this.editDialog = false
        this.cardDialogVisible = false
        this.$refs.${modelName?uncap_first}Ref.$refs.${modelName?uncap_first}Form.resetFields()
      }
    },
    name: '${moduleName}-${modelName?uncap_first}',
    components: {
      '${vueTab?uncap_first}-list': ${modelName?cap_first}List,
      'zk-edit-${vueTab?uncap_first}': ZkEdit${modelName?cap_first}
    }
  }
</script>
